package priv.bestbeat.reportcenter.core.monitor;

import priv.bestbeat.reportcenter.core.task.Task;
import priv.bestbeat.reportcenter.core.task.states.TaskStateEnum;
import priv.bestbeat.reportcenter.core.utils.SnowflakeUtil;

/**
 * 任务监控代理
 * @author 张渠钦
 * @date 2022/4/24 15:42
 */
public class TaskMonitorProxy extends MonitorProxy<Task> {

    @Override
    public Observable<Task, ?> register(Task obj) {
        TaskObservable observable = new TaskObservable();
        observable.setId(SnowflakeUtil.getId());
        observable.setObj(obj);
        observable.setState(TaskStateEnum.NEW);

        getPersistenceProxy().persist(observable);
        return observable;
    }

    @Override
    public Observable changeState(Observable obj) {
        TaskObservable nowObject= (TaskObservable) getPersistenceProxy().getById(obj);
        nowObject.setState(obj.getState());
        getPersistenceProxy().update(nowObject);
        return nowObject;
    }


}
